{% extends "BillingBundle::user_layout.html.twig" %}

{% macro field(row, lname, label) %}
    <tr>
        <td class="label">
            <label id="l{{ lname }}" for="{{ lname }}">{{ label }}:</label>
        </td>
        <td class="field">
            {{ form_widget(row) }}
        </td>
        <td class="status"></td>
        <td>
            {{ form_errors(row) }}
        </td>
    </tr>
{% endmacro %}

{% block content %}

<link rel="stylesheet" type="text/css" media="screen" href="{{ asset('bundles/billing/css/validate.css') }}" />
<script src="{{ asset('bundles/billing/js/jquery.js') }}" type="text/javascript"></script>
<script src="{{ asset('bundles/billing/js/jquery.validate.js') }}" type="text/javascript"></script>


<h4>Изменение информации о пользователе:</h4>

<div id="add_box">
  <div id="add_wrap">
    <form id="add_form" method="post" action="#">
        <table>
           {{ _self.field(form.login, 'login', 'E-mail (в качестве логина)') }}
           {{ _self.field(form.password, 'password', 'Пароль') }}
           {{ _self.field(form.password_confirm, 'password_confirm', 'Пароль второй раз') }}
           {{ form_widget(form._token) }}
        <tr>
            <td>
            <div class="field">
                <input name="add_order" type="submit" value="Изменить" onClick="updateScript()"/>
            </div>
            </td>
        </tr>
        </table>
    </form>
   </div>
</div>

<script type="text/javascript">
function updateScript()
{
    (function($) {
$(document).ready(function()
{
    var password = document.getElementById('user_password').value;
    var password_confirm = document.getElementById('user_password_confirm').value;
    if (password != '' || password_confirm != '')
    {
        var validator = $("#add_form").validate({
            rules: {
                'user[login]': {
                        required: true,
                        maxlength: 30,
                        email: true
                },
                'user[password]': {
                        required: true,
                        minlength: 3,
                        maxlength: 15
                },
                'user[password_confirm]': {
                        required: true,
                        minlength: 3,
                        maxlength: 15,
                        equalTo: '#user_password'
                }
            },
            messages: {
                'user[login]': {
                        required: "Введите e-mail",
                        maxlength: "Максимальная длина 30 символов",
                        email: "Введите корректный e-mail"
                },
                'user[password]': {
                        required: "Введите пароль",
                        minlength: "Минимальная длина 3 символа",
                        maxlength: "Максимальная длина 15 символов"
                },
                'user[password_confirm]': {
                        required: "Повторите пароль",
                        minlength: "Минимальная длина 3 символа",
                        maxlength: "Максимальная длина 15 символов",
                        equalTo: "Пароли не совпадают"
                }
            },

            errorPlacement: function(error, element) {
                if ( element.is(":radio") )
                        error.appendTo( element.parent().next().next() );
                else if ( element.is(":checkbox") )
                        error.appendTo ( element.next() );
                else
                        error.appendTo( element.parent().next() );
            },

            submitHandler: function() {

                form.submit();
            },

            success: function(label) {
                // set &nbsp; as text for IE
                label.html("&nbsp;").addClass("checked");
            }
        });
    }
});
})(jQuery);
}
</script>
{% endblock %}

